function init() {
	var productId = GetQueryString("productId");
    var productUnit = "";
    $('.tab ul').on('click','li',function(){
        $(this).addClass('active').siblings().removeClass('active');
    });
    // 图片左右滚动
    var count = $(".img-list li").length - 3;
    /* 显示 3 个 li标签内容 */
    //var interval = $(".img-list li:first").width();
    var interval = 100;
    var curIndex = 0;
    $('.scrollbutton').click(function () {
    	var count = $(".img-list").find('li').length - 1;
        if ($(this).hasClass('disabled')){
            return false;
        }
        if ($(this).hasClass('left-arrow')){
            --curIndex;
        } else{
            ++curIndex;
        }
        $('.scrollbutton').removeClass('disabled');
        if (curIndex == 0){
            $('.left-arrow').addClass('disabled');
        }
        if (curIndex == count){
            $('.right-arrow').addClass('disabled');
        }
        $(".img-list ul").stop(false, true).animate({"marginLeft": -curIndex * interval + "px"}, 250);
    });
    $('.img-list ul').on('click','li',function(){
        var src=$(this).children('img').attr('src');
        $('.big-img').children('img').attr('src',src);
       $(this).children('img').addClass('chose').parent('li').siblings('li').children('img').removeClass('chose');
    });


    $('.spec_list').on('click','.spec_item p',function(){
        $(this).addClass('chose').siblings('p').removeClass('chose');
        getPrice();
    });
//    加载商品信息
    $.ajax({
		type:"POST",
		url:path+"/product/product/productByProductId",
		data:{"productId":productId},
		success:function(data){
			productUnit = data.data.littleUnitName
			$('.product-name').html(data.data.productName);
			$('.productCate').html(data.data.categoryName);
			$('.productBrand').html(data.data.brandName);
			$('.productCode').html(data.data.productCode);
			$('.productUnit').html(data.data.littleUnitName);
			$('.productKeyWord').html(data.data.keyWord == ""? '无':data.data.keyWord);
			$('.isSell').html(data.data.isRelease == "1"?"上架":"下架");
			$('.pro-content').html(data.data.productDetail);
		}
	});
//    加载商品图片和附件
    $.ajax({
		type:"POST",
		url:path+"/productAttachment/productAttachment/attaListByProductId",
		data:{"productId":productId},
		success:function(data){
			var list = data.data;
			var html = "";
			for(var i = 0;i<list.length;i++){
				if(list[i].type == "0"){
					html += "<li><img src='/docs/"+list[i].url+"'/></li>";
				}
			}
			$('.img-list ul').html(html);
			$('.big-img').find('img').attr('src','/docs/'+list[0].url);
		}
	});
//    加载商品规格相关
    $.ajax({
		type:"POST",
		url:path+"/orderlang/specification/specList",
		data:{"productId":productId},
		success:function(data){
			var specList = data.data;
			var html = "";
			for(var i = 0;i<specList.length;i++){
				var specValue = specList[i].specValue.split(',');
				html += "<div class='spec_item'>";
				html += "<div>";
				html += "<h4 class='fl'>"+specList[i].specName+"</h4>";
				for(var j = 0;j<specValue.length;j++){
					if(j == 0){
						html += "<p class='chose'>"+specValue[j]+"</p>";
					}else{
						html += "<p>"+specValue[j]+"</p>";
					}
				};
				html += "</div>";
				html += "</div>"
			}
			$('.spec_list').html(html);
			getPrice();
		}
	});
  //加入购物车
    $('.to-buy').on('click',function(e){
    	e.preventDefault();
    	var priceId = $(this).parent().attr('data-id');
    	var quantity = Number($('.quantity').val());
    	var moq = Number($('.moq').find('span:nth-child(1)').html());
    	var invertory = Number($('.count').find('.invertory').html());
    	if(quantity == 0){
			layer.msg("订购数量不能为0", {icon: 2,time:1000});
    	}else if(!(isPositiveInteger(quantity))){
    		layer.msg("请输入正确的订购数量", {icon: 2,time:1000});
    	}else if(quantity < moq){
    		layer.msg("订购数量不能小于起订量", {icon: 2,time:1000});
    	}else if(quantity > invertory){
    		layer.msg("订购数量不能超过商品库存", {icon: 2,time:1000});
    	}else if(quantity >= moq && quantity <= invertory ){
        		$.ajax({
    				type:"POST",
    				url:path+"/orderlang/userCart/save",
    				data:{"productId":productId,
    						"productPriceId":priceId,
    						"quantity":quantity
    						},
    				success:function(data){
    						if(data.state == 1){
    							layer.msg("添加购物车成功", {icon: 1,time:1000},function(){
    								//window.location.href=path+"; 
    							});
    						}else{
    							layer.msg("添加购物车失败，请重试", {icon: 2,time:2000});
    						}
    				}
    			});
        	}
    });
  //根据选中规格读取商品价格信息
    function getPrice(){
	    var specList = [];
	    $('.spec_list p').each(function(){
	    	if($(this).hasClass('chose')){
	    		specList.push($(this).html());
	    	}
	    })
	    specList = specList.join(',');
	    $.ajax({
			type:"POST",
			url:path+"/productPrice/productPrice/findPriceBySpecValue",
			data:{
				"productId":productId,
				"specValue":specList
			},
			success:function(data){
				if(data.state == 1){
					var product = data.data.productPrice;
					$('.orderPrice').find('b').html(cc(product.marketPrice.toString()));
					$('.moq').find('span:nth-child(1)').html(product.moq);
					$('.moq').find('span:nth-child(2)').html(productUnit);
					$('.count').find('.invertory').html(data.data.quantity);
					$('.count').find('.unit').html(productUnit);
					$('.buy').attr('data-id',product.id);
				}else{
					layer.msg(data.msg, {icon: 2,time:1000});
					$('.orderPrice').find('b').html(cc('0'));
					$('.moq').find('span:nth-child(1)').html('0');
					$('.count').find('.invertory').html('0');
					$('.count').find('.unit').html(productUnit);
					$('.buy').attr('data-id',"");
				}
			}
		});
    };
    function isPositiveInteger(s){//是否为正整数
        var re = /^[0-9]+$/ ;
        return re.test(s)
    }
}
init();
//加入收藏
//$('.collect').on('click',function(){
//	console.log("aaaa");
//	var path = getRootPath();
//	var id = $('.parameter').attr('data-id');
//	$.ajax({
//		type:"GET",
//		url:path+"/collect/collectOneProduct",
//		data:{"id":id
//				},
//		success:function(data){
//				if(data.isSuccess==0){
//					alertBox(0,data.msg);
//				}else{
//					alertBox(1,data.data);
//				}
//		}
//	})
//})
